﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace opentk_first_project
{
    class FrameCounter
    {
        private static long current_fps = 0;
        private static double start_time = 0;
        private static long frames = 0;
        public FrameCounter()
        {
        }

        public static long get_framerate() { return current_fps; }

        public static void reset()
        {
            current_fps = 0;
            start_time = 0;
            frames = 0;
        }
        public static void frame_shown()
        {
            frames++;
            double current_time = DateTime.Now.TimeOfDay.TotalMilliseconds;
            if (start_time == 0)
            {
                start_time = current_time;
            }
            else
            {
                long delta_time = (long)(current_time - start_time);
                if (delta_time < 0 || delta_time > 2000)
                {
                    if (delta_time > 0)
                        current_fps = (frames * 1000) / delta_time;
                    frames = 0;
                    start_time = current_time;
                }
            }
        }
    }
}
